<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <style>
        div{padding:10px;margin:10px;border:solid 1px black;}
    </style>
</head>
<body>
    <div class="app">
        <h1>这是 - {{title}}</h1>
        <p>这是子组件传过来的：{{d}}</p>
        <Child1 @my-eve="onMyEve"></Child1>
    </div>
</body>
<template id="child1Temp">
    <div>
        <h3>这是 - {{title}}</h3>
        <p>子组件的数据为：{{msg}}</p>
        <input type="button" value="向父组件发送数据" @click="send">
    </div>
</template>
<script src="../vue.global.js"></script>
<script>
    const app = Vue.createApp({
        data(){
            return {
                title: "根组件",
                d:""
            }
        },
        methods:{
            onMyEve(a){
                console.log(a)
                this.d = a;
            }
        },
        components:{
            Child1: {
                data(){
                    return {
                        title:"子组件1",
                        msg: "子组件的数据"
                    }
                },
                template:"#child1Temp",
                created() {
                    // this.$emit("myEve", this.msg)
                },
                methods:{
                    send(){
                        this.$emit("myEve", this.msg);
                    }
                },
                emits:["myEve"]
            }
        }
    })

    app.mount(".app");

</script>
</html>